import { request } from '@/utils/request'

interface ChatMessage {
  role: 'user' | 'assistant'
  content: string
}

export interface LocalChatMessage {
  role: 'ME' | 'AI'
  content: string
}

// 转换函数：将本地消息格式转换为API所需格式
const convertToApiFormat = (msg: LocalChatMessage): ChatMessage => ({
  role: msg.role === 'ME' ? 'user' : 'assistant',
  content: msg.content
})

export interface AIChatParams {
  mode: 'naive' | 'local' | 'global' | 'hybrid'
  top_k: number
  max_token_for_text_unit: number
  max_token_for_global_context: number
  max_token_for_local_context: number
  history_turns: number
  only_need_context: boolean
  only_need_prompt: boolean
  stream: boolean
  query: string
  conversation_history?: ChatMessage[]
}

// 与后端 AI 服务对话
export const aiChat = (params: AIChatParams) => {
  return request.post('/ai/chat', params)
}
